package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.pojo.SubClassInfoRequest;
import cn.stylefeng.guns.modular.business.service.SubClassInfoService;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 课程数据控制器
 *
 * @author zhangyaowen
 * @date 2021/08/18 14:09
 */
@RestController
@ApiResource(name = "课程数据")
public class SubClassInfoController {

    @Resource
    private SubClassInfoService subClassInfoService;

    /**
     * 添加
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "添加", path = "/subClassInfo/add")
    public ResponseData add(@RequestBody @Validated(SubClassInfoRequest.add.class) SubClassInfoRequest subClassInfoRequest) {
        subClassInfoService.add(subClassInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "删除", path = "/subClassInfo/delete")
    public ResponseData delete(@RequestBody @Validated(SubClassInfoRequest.delete.class) SubClassInfoRequest subClassInfoRequest) {
        subClassInfoService.del(subClassInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "编辑", path = "/subClassInfo/edit")
    public ResponseData edit(@RequestBody @Validated(SubClassInfoRequest.edit.class) SubClassInfoRequest subClassInfoRequest) {
        subClassInfoService.edit(subClassInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "查看详情", path = "/subClassInfo/detail")
    public ResponseData detail(@Validated(SubClassInfoRequest.detail.class) SubClassInfoRequest subClassInfoRequest) {
        return new SuccessResponseData(subClassInfoService.detail(subClassInfoRequest));
    }

    /**
     * 获取列表
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "获取列表", path = "/subClassInfo/classList")
    public ResponseData classList(String className) {
        boolean superAdmin = LoginContext.me().getSuperAdminFlag();
        if(superAdmin) {
            SubClassInfoRequest subClassInfoRequest = new SubClassInfoRequest();
            subClassInfoRequest.setClassName(className);
            return new SuccessResponseData(subClassInfoService.findList(subClassInfoRequest));
        }else{
            return new SuccessResponseData("201","no permission","");
        }
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "分页查询", path = "/subClassInfo/page")
    public ResponseData page(String className) {
        boolean superAdmin = LoginContext.me().getSuperAdminFlag();
        if(superAdmin) {
            SubClassInfoRequest subClassInfoRequest = new SubClassInfoRequest();
            subClassInfoRequest.setClassName(className);
            return new SuccessResponseData(subClassInfoService.findPage(subClassInfoRequest));
        }else{
            return new SuccessResponseData("201","暂无权限，请联系管理员！","");
        }
    }

    @GetResource(name = "详情", path = "/subClassInfo/toReview")
    public ResponseData toBookReview(String id) {
        return new SuccessResponseData(subClassInfoService.toReview(id));
    }

}